package com.xiaotu.controller;

import com.xiaotu.entity.Person;
import com.xiaotu.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private PersonService personService;
    @GetMapping("list")
    @ResponseBody
    public List<Person> list(){
        List<Person> all = personService.findAll();
        return  all;
    }
    @DeleteMapping("delete/{id}")
    @ResponseBody
    public String delete(@PathVariable("id") Long id){
        personService.delete(id);
        return  "删除成功";
    }
    @PostMapping("/add")
    @ResponseBody
    public String add(Person person){
        personService.add(person);
        return "添加成功";
    }
    @PutMapping("/update")
    @ResponseBody
    public String update(Person person){
        personService.update(person);
        return "修改成功";
    }
}
